<include file="public@header" />
</head>
<body>
	<php>$results=''</php>
	<div class="wrap ">
		<ul class="nav nav-tabs">
			<li><a href="{:url('Construction/index')}">项目管理</a></li>
			<li><a href="{:url('Construction/add')}">发起项目</a></li>
			<li class="active"><a href="{:url('Construction/apply')}">物料申购</a></li>
		</ul>
		<form  class="form-horizontal js-ajax-form" method="post" action="{:url('Construction/applyadd_post')}" enctype="multipart/form-data">
			<input type="hidden" name="porject_id" value="{$porject_id}">
        	<table class="table table-hover table-bordered">
				<thead>
					<tr>
						<th align="left" width="15%">ID <div class="btn btn-success" id="check-pro">选择产品</div></th>
						<th align="left" width="10%">编号</th>
						<th align="left" width="10%">物料名称</th>
                        <th align="left" width="8%">价格</th>
						<th align="left" width="8%">单位</th>
						<th align="left" width="10%">税金</th>
						<th align="left" width="10%">数量</th>
                        <th align="left" width="10%">金额</th>
                        <th align="left" width="10%">所属库房</th>
                        <th align="left" width="10%">库存量</th>
					</tr>
				</thead>
				<tbody>
				<tbody id="pro_tr" >
				</tbody>
			</table>
			<div class="form-actions">
				<button type="submit" class="btn btn-primary js-ajax-submit">提交</button>
			</div>
		</form>
	</div>
	<script type="text/javascript" src="__STATIC__/js/admin.js?v={:time()}"></script>
	<script>
		$('#check-pro').click(function () {
			openIframeLayer("{:url('ajaxproduct')}?type=0", '请选择物料', {
				area: ['90%', '85%'],
				btn: ['确定', '取消'],
				yes: function (index, layero) {
					var iframeWin          = window[layero.find('iframe')[0]['name']];
					var selectedProduct = iframeWin.confirm();
					if (selectedProduct.goodsId.length == 0) {
						layer.msg('请选择产品');
						return;
					}

					$.each(selectedProduct.productList, function (i, n) {
						if ( $('#pro_tr').find('tr').hasClass('id_'+n.id)){
							var  class_pro = $('#pro_tr').find('.id_'+n.id);
							// class_pro.find('.num').val(parseInt(class_pro.find('.num').val())+1)
						}else {
							var ii = n.id;
							var  html_tr ='<tr class="id_'+n.id +'">\n' +
									'   <td>\n' +
									'    <input type="hidden" class="form-control id" name="product['+ii+'][id]" value="'+n.id+'">' + n.id +
									'    </td>' +
									'    <td>'+n.goods_num+'</td>' +
									'    <td>'+n.goods_name+'</td>' +
									'    <td>'+n.price+'<input type="hidden" class="form-control price" name="product['+ii+'][price]" value="'+n.price+'"></td>' +
									'    <td>'+n.price_unit+'</td>' +
									'    <td><input type="number" class="form-control tax_money " min="0" name="product['+ii+'][tax_money]" value=""></td>' +
									'    <td><input type="number" class="form-control num" min="0" name="product['+ii+'][num]" value=""></td>' +
									'    <td><input type="text" class="form-control total_price" name="product['+ii+'][total_price]" value=""></td>' +
									'    <td>'+n.room_name+'</td>' +
									'    <td>'+n.stock+'</td>' +
									'</tr>';
							$('#pro_tr').append(html_tr);
						}
					})

					layer.close(index); //如果设定了yes回调，需进行手工关闭
				}
			});
		});
		$(document).on("blur",'.num',function (event) {
			var k = event.target.offsetLeft,target  = event.target,total=0,
			className = $(target).parent().parent()[0].className;
			var unit_price = $('.'+className).find(".price").val(),
					num =event.target.value;

			var tax_money = $('.'+className).find(".tax_money").val();

            unit_price = unit_price?unit_price:0;
            num = num?num:0;
            tax_money = tax_money?tax_money:0;
			$('.'+className).find('.total_price').val((num * unit_price)+parseInt(tax_money));

		})
	</script>
    
</body>
</html>




